package com.swu.pad.analysis.service.impl;

import java.io.Console;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;

import javax.management.MBeanConstructorInfo;

import org.aspectj.weaver.ast.Var;
import org.aspectj.weaver.patterns.TypePatternQuestions.Question;
import org.hibernate.boot.model.source.spi.SecondaryTableSource;
import org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mchange.util.impl.LinkedListIntChecklistImpl;
import com.swu.pad.activity.dao.ActivityDao;
import com.swu.pad.activity.entity.Activity;
import com.swu.pad.analysis.service.AnalysisService;
import com.swu.pad.assignment.dao.AssignmentDao;
import com.swu.pad.assignment.dao.AssignmentPadDao;
import com.swu.pad.assignment.entity.Assignment;
import com.swu.pad.assignment.entity.AssignmentPad;
import com.swu.pad.assignment.service.AssignmentService;
import com.swu.pad.comment.dao.CommentDao;
import com.swu.pad.comment.dao.CommentQuestionDao;
import com.swu.pad.comment.dao.FbCommentDao;
import com.swu.pad.comment.dao.FbCommentGradeDao;
import com.swu.pad.comment.entity.Comment;
import com.swu.pad.comment.entity.CommentQuestion;
import com.swu.pad.comment.entity.FbComment;
import com.swu.pad.comment.entity.FbCommentGrade;
import com.swu.pad.course.dao.CourseGroupUserDao;
import com.swu.pad.course.dao.GroupDao;
import com.swu.pad.course.entity.Course;
import com.swu.pad.course.entity.CourseGroupUser;
import com.swu.pad.course.entity.Group;
import com.swu.pad.course.service.CourseService;
import com.swu.pad.system.dao.UserDao;
import com.swu.pad.system.entity.User;
import com.swu.pad.system.service.UserService;
import com.swu.pad.util.EPLiteClient.EPLiteClient;

@Service
@Transactional
public class AnalysisServiceImpl implements AnalysisService {

	@Autowired
	private ActivityDao activityDao;
	@Autowired
	private UserService userService;
	@Autowired
	private AssignmentDao assignmentDao;
	@Autowired
	private AssignmentPadDao assignmentPadDao;
	@Autowired
	private CourseGroupUserDao courseGroupUserDao;
	@Autowired
	private CommentDao commentDao;
	@Autowired
	private CommentQuestionDao commentQuestionDao;
	@Autowired
	private AssignmentService assignmentService;
	@Autowired
	private CourseService courseService;
	@Autowired
	private GroupDao groupDao;
	@Autowired
	private EPLiteClient epliteClient;
	@Autowired
	private FbCommentDao fbCommentDao;
	@Autowired
	private UserDao userDao;
	@Autowired
	private FbCommentGradeDao fbCommentGradeDao;

	// 权重树
	public static TreeMap<Integer, Float> weightTree = new TreeMap<Integer, Float>();
	static {
		// [0,30]->1.0 (30,45]->0.8 (45,60]->0.6 (60,75]->0.4 (75,90]->0.2
		// (90,)->0.0
		weightTree.put(-1, (float) 1.0);
		weightTree.put(30, (float) 0.8);
		weightTree.put(45, (float) 0.6);
		weightTree.put(60, (float) 0.4);
		weightTree.put(75, (float) 0.2);
		weightTree.put(90, (float) 0.0);
	}

	/**
	 * 组内雷达图
	 * 
	 * @throws Exception
	 */
	public Map<String, Object> getGroupRadar(String activityId, User user) throws Exception {
		// 组内雷达图
		// {assignment:'',group:'',radar:[{user:'',radar:[{question:'',score:''}]}]}
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		// courseGroupUserList存放所有本组组员信息
		List<CourseGroupUser> courseGroupUserList = courseService.getUserAssignmentGroup(user.getId(),
				activity.getAssignmentId(), assignment.getAssignmentType());

		// map 最终反馈给前台的数据集合
		Map<String, Object> map = new HashMap<String, Object>();

		// map 两个键位 确定本次作业
		map.put("assignmentId", assignment.getId());
		map.put("assignmentName", assignment.getAssignmentName());

		// map radar 键位 数据结构 list
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		List<Map<String, Object>> groupScoreList = new ArrayList<Map<String, Object>>();
		List<CommentQuestion> commentQuestionList1 = commentQuestionDao
				.findByTemplateId(assignment.getMutualTemplateId());
		List<String> questionList = new ArrayList<String>();
		// 判断 如果 本组成员不为空 再执行以下操作
		if (courseGroupUserList != null && courseGroupUserList.size() > 0) {

			// map 加入一个键位 组名称
			map.put("groupName", courseGroupUserList.get(0).getGroupName());

			// 查询本组此时所属的作业pad
			String groupId = courseGroupUserList.get(0).getGroupId();
			AssignmentPad assignmentPad = assignmentService.getUserAssignmentPad(assignment.getId(), groupId);
			// 做 本组人数次循环 s
			for (int i = 0; i < courseGroupUserList.size(); i++) {
				// 每次循环 创建一个新的 tempMap 类型为 map
				Map<String, Object> tempMap = new HashMap<String, Object>();

				// 向 tempMap 里加入一个 键位 user ,值为 组成员名称
				tempMap.put("user", courseGroupUserList.get(i).getUserName());

				// 创建一个评论问题list 用来存放 评论问题的 类型 (也就是 前台对应的星级 的 名称)
				List<CommentQuestion> commentQuestionList = commentQuestionDao
						.findByTemplateId(assignment.getMutualTemplateId());

				// 创建一个tempList 类型为 list 存放map
				List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>();

				// 根据评论维度 做循环
				for (int j = 0; j < commentQuestionList.size(); j++) {
					// 创建一个 commet list 用来存放所有的 comment 信息 ，查询条件 ：当前 作业padid
					// 组员id ，评论维度的id （目的是获取当前维度的分数）
					List<Comment> commentList = commentDao.findByAssignmentPadIdAndAuthorIdAndQuestionId(
							assignmentPad.getId(), courseGroupUserList.get(i).getUserId(),
							commentQuestionList.get(j).getId());// 当前循环人所得道德所有评论列表
					// 如果 comment 查询没有空 ，说明 当前用户 有人给他评分
					if (commentList != null && commentList.size() > 0) {
						// 则创建一个新的 map 存放question （互评模板的 维度）
						Map<String, Object> tempMap0 = new HashMap<String, Object>();
						tempMap0.put("question", commentQuestionList.get(j).getQuestion());
						// 存放在当前维度所得分数的分数
						List<Integer> indexList = new ArrayList<Integer>();
						for (int n = 0; n < courseGroupUserList.size(); n++) {
							int index = -1;
							String DateStr = "2000-00-00 00:00:0";
							DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
							Date compreDate = df.parse(DateStr);
							if (!courseGroupUserList.get(n).getUserId()
									.equals(courseGroupUserList.get(i).getUserId())) {// 作者和本次循环的不相同
								for (int m = 0; m < commentList.size(); m++) {
									if (commentList.get(m).getCommenterId()
											.equals(courseGroupUserList.get(n).getUserId())) {
										if (commentList.get(m).getCommentTime().compareTo(compreDate) > 0) {
											compreDate = commentList.get(m).getCommentTime();
											index = m;
											// System.out.println(compreDate);
										}
									}
									// 找到当前评论人的最新评论
								}

								indexList.add(index);
							}
						}

						double score = 0;
						int count = 0;
						// 计算平均分
						for (int k = 0; k < indexList.size(); k++) {
							//System.out.println("indexList" + indexList.get(k));
							if (indexList.get(k) != -1) {
								count++;
								score += Double.parseDouble(commentList.get(indexList.get(k)).getScore());
							}
							//System.out.println("score" + score);
						}
						// 存一个键位 分数
						//System.out.println(indexList.size());
						if (count == 0) {
							tempMap0.put("score", (score + 0.0));
						} else {
							tempMap0.put("score", (score + 0.0) / count);
						}
						// 将 question score（平均分放入tempList）
						tempList.add(tempMap0);

					} // tempList填充完毕

					tempMap.put("tempList", tempList);

				}

				list.add(tempMap);

			} // 做 本组人数次循环 end

		} // if end
		for (int i = 0; i < commentQuestionList1.size(); i++) {
			questionList.add(commentQuestionList1.get(i).getQuestion());
		}
		map.put("question", questionList);
		map.put("radar", list);

		return map;
	}

	/**
	 * 获取班级雷达图
	 * 
	 * @throws Exception
	 */
	public Map<String, Object> getMutualCourseRadar(String activityId, User user) throws Exception {
		// 班级雷达图
		// {assignment:'',group:'',radar:[{user:'',radar:[{question:'',score:''}]}]}

		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		// 找到该用户所属的 班级的所有小组
		List<CourseGroupUser> courseGroupUserList1 = courseService.getUserAssignmentGroup(user.getId(),
				activity.getAssignmentId(), assignment.getAssignmentType());
		String groupName = courseGroupUserList1.get(0).getGroupName();
		List<Group> groups = groupDao.findGroupByCourseIdAndGroupType(assignment.getCourseId(),
				courseGroupUserList1.get(0).getGroupType());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("assignmentId", assignment.getId());
		map.put("assignmentName", assignment.getAssignmentName());
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		List<CommentQuestion> commentQuestionList = commentQuestionDao
				.findByTemplateId(assignment.getMutualTemplateId());
		double[][] groupScore = new double[groups.size()][commentQuestionList.size()];// 存放所有分数
		if (groups != null && groups.size() > 0) {
			//遍历班级所有组
			for (int m = 0; m < groups.size(); m++) {
				Map<String, Object> groupRadar = new HashMap<String, Object>();
				List<CourseGroupUser> courseGroupUserList = courseGroupUserDao
						.findCourseGroupUserByGroupId(groups.get(m).getId());
				Map<String, Object> tempMap = new HashMap<String, Object>();
				if (courseGroupUserList != null && courseGroupUserList.size() > 0) {
					//获取每个组的pad
					String groupId = courseGroupUserList.get(0).getGroupId();
					AssignmentPad assignmentPad = assignmentService.getUserAssignmentPad(assignment.getId(), groupId);
					// 做 本组人数次循环 s
					List<Double> scoreList = new ArrayList<Double>();
					List<String> questionList = new ArrayList<String>();
					int[] courseCount = new int[commentQuestionList.size()];
					//循环维度
					for (int i = 0; i < commentQuestionList.size(); i++) {
						questionList.add(commentQuestionList.get(i).getQuestion());
						double tempScore = 0;
						Double[] questionScore = new Double[courseGroupUserList.size()];
						for (int j = 0; j < questionScore.length; j++) {
							questionScore[j] = (double) 0;
						}
						//遍历组内所有人
						for (int j = 0; j < courseGroupUserList.size(); j++) {
							int[] commentIndex = new int[courseGroupUserList.size()];
							for (int k = 0; k < commentIndex.length; k++) {
								commentIndex[k] = -1;
							}
							List<Comment> commentList = commentDao.findByAssignmentPadIdAndAuthorIdAndQuestionId(
									assignmentPad.getId(), courseGroupUserList.get(j).getUserId(),
									commentQuestionList.get(i).getId());
							//获取最新一条评论
							for (int k = 0; k < courseGroupUserList.size(); k++) {
								// System.out.println(k);
								if (!(courseGroupUserList.get(j).getUserId()
										.equals(courseGroupUserList.get(k).getUserId()))) {
									String DateStr = "2000-00-00 00:00:0";
									DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
									Date compreDate = df.parse(DateStr);
									// System.out.println(k);
									for (Comment comment : commentList) {
										if (comment.getCommenterId().equals(courseGroupUserList.get(k).getUserId())) {
											if (comment.getCommentTime().compareTo(compreDate) > 0) {
												compreDate = comment.getCommentTime();
												// System.out.println(commentList.size());
												for (int n = 0; n < commentList.size(); n++) {
													// System.out.println(n);
													if (commentList.get(n).equals(comment)) {
														commentIndex[k] = n;

														// System.out.println(commentList.get(n).getScore());
													}
												}
												// System.out.println("in");
											}
										}
									}
								}
							}
							//计算组内平均分
							int count = 0;
							for (int k = 0; k < commentIndex.length; k++) {
								if (commentIndex[k] != -1) {
									// System.out.println(commentList.get(commentIndex[k]).getScore());
									count++;
									questionScore[j] += Double.parseDouble(commentList.get(commentIndex[k]).getScore());
								}
							}
							// System.out.println("over");
							// System.out.println(questionScore[j]);
							if (questionScore[j] == null)
								continue;
							count = count==0?1:count;
							questionScore[j] = questionScore[j] / count;
						}
						//计算班级平均分
						int count = 0;
						for (int j = 0; j < courseGroupUserList.size(); j++) {
							// System.out.println(questionScore[j]);
							if (questionScore[j] == 0) {
								tempScore += 0;
							} else {
								count++;
								tempScore += questionScore[j];
							}
						}
						//System.out.println("tempScore:"+tempScore+"courseCount"+count);
						count = count==0?1:count;
						scoreList.add(tempScore/count);
					}

					for (int i = 0; i < commentQuestionList.size(); i++) {
						groupScore[m][i] = scoreList.get(i).doubleValue();
					}
					tempMap.put("score", scoreList);
					tempMap.put("question", questionList);
				}

				groupRadar.put("groupName", groups.get(m).getGroupName());
				groupRadar.put("radar", tempMap);
				list.add(groupRadar);

			}

		} // 获取到所有组数据

		// list数据处理 班级平均值 radar[，，，，] 班级最大值 radar [,,,,] 本组值
		List<Double> maxScoreInCourse = new ArrayList<Double>();
		List<Double> avgScoreInCourse = new ArrayList<Double>();
		List<Double> myGroupScoreInCourse = new ArrayList<Double>();
		List<String> question = new ArrayList<String>();
		List<Map<String, Object>> newList = new ArrayList<Map<String, Object>>();
		for (CommentQuestion commentQuestion : commentQuestionList) {
			question.add(commentQuestion.getQuestion());
		}
		double score = 0;

		int index = 0;
		for (int i = 0; i < groups.size(); i++) {
			if (groups.get(i).getGroupName().equals(groupName)) {
				index = i;
			}
		}
		// 取出本小组数据
		for (int i = 0; i < list.size(); i++) {
			if (groupName.equals(list.get(i).get("groupName").toString())) {
				// courseFinalList.add(list.get(i));//将本小组数据存放入最终数据中
				for (int j = 0; j < commentQuestionList.size(); j++) {
					myGroupScoreInCourse.add(groupScore[index][j]);
				}
			}
		}
		// 取出全班在 各个维度的最大值 存入maxScoreInCourse list里
		double avg = 0;
		for (int i = 0; i < commentQuestionList.size(); i++) {
			for (int j = 0; j < groups.size(); j++) {
				if (score < groupScore[j][i]) {
					score = groupScore[j][i];
				}
				avg += groupScore[j][i] / groups.size();
			}
			maxScoreInCourse.add(score);
			avgScoreInCourse.add(avg);
			score = 0;
			avg = 0;
		}
		// 取出全班在各个维度的平均值
		// 最终存入list

		Map<String, Object> avgGroupRadar = new HashMap<String, Object>();
		Map<String, Object> maxGroupRadar = new HashMap<String, Object>();
		Map<String, Object> myGroupRadar = new HashMap<String, Object>();
		// 本组

		// 最大

		// 平均

		for (int i = 0; i < 3; i++) {
			Map<String, Object> Radar = new HashMap<String, Object>();
			if (i == 0) {
				if (assignment.getAssignmentType().equals("1")) {

					myGroupRadar.put("groupName", "本人");
				} else {
					myGroupRadar.put("groupName", "本小组");
				}
				Radar.put("score", myGroupScoreInCourse);
				Radar.put("question", question);
				myGroupRadar.put("radar", Radar);
				newList.add(myGroupRadar);
			} else if (i == 1) {
				avgGroupRadar.put("groupName", "班级平均值");
				avgGroupRadar.put("question", question);
				Radar.put("score", avgScoreInCourse);
				Radar.put("question", question);
				avgGroupRadar.put("radar", Radar);
				newList.add(avgGroupRadar);
			} else {
				maxGroupRadar.put("groupName", "班级最大值");
				Radar.put("score", maxScoreInCourse);
				Radar.put("question", question);
				maxGroupRadar.put("radar", Radar);
				newList.add(maxGroupRadar);
			}
		}
		map.put("question", question);
		map.put("radar", newList);

		return map;
	}

	public Map<String, Object> getCourseRadar(String activityId, User user) {
		// 组间雷达图
		// {assignment:'',group:'',radar:[{user:'',radar:[{question:'',score:''}]}]}
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("assignmentId", assignment.getId());
		map.put("assignmentName", assignment.getAssignmentName());
		List<CommentQuestion> commentQuestionList = commentQuestionDao
				.findByTemplateId(assignment.getReplyTemplateId());
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		List<AssignmentPad> assignmentPadList = assignmentPadDao.findAssignmentPadByAssignmentId(assignment.getId());
		for (int j = 0; j < commentQuestionList.size(); j++) {
			int score = 0, count = 0;
			Map<String, Object> tempMap = new HashMap<String, Object>();
			for (int i = 0; i < assignmentPadList.size(); i++) {
				List<Comment> commentList = commentDao.findByAssignmentPadIdAndQuestionId(
						assignmentPadList.get(i).getId(), commentQuestionList.get(j).getId());
				if (commentList != null && commentList.size() > 0) {
					for (int k = 0; k < commentList.size(); k++) {
						score += Integer.parseInt(commentList.get(k).getScore());
					}
					count += commentList.size();
				}
			}
			tempMap.put("question", commentQuestionList.get(j).getQuestion());
			tempMap.put("score", count == 0 ? 0.0 : (score + 0.0) / count);
			list.add(tempMap);
		}
		map.put("radar", list);

		return map;
	}

	public Map<String, Object> getGroupWordPie(String activityId, User user) {
		// 组内饼图 {assignment:'',group:'',pie:[{user:'',word:''}]}
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		List<CourseGroupUser> courseGroupUserList = courseService.getUserAssignmentGroup(user.getId(),
				activity.getAssignmentId(), assignment.getAssignmentType());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("assignmentId", assignment.getId());
		map.put("assignmentName", assignment.getAssignmentName());
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		if (courseGroupUserList != null && courseGroupUserList.size() > 0) {
			map.put("groupName", courseGroupUserList.get(0).getGroupName());
			String groupId = courseGroupUserList.get(0).getGroupId();
			AssignmentPad assignmentPad = assignmentService.getUserAssignmentPad(assignment.getId(), groupId);
			List authorList = epliteClient.listAuthorsOfPad(assignmentPad.getId());
			for (int i = 0; i < authorList.size(); i++) {
				Map<String, Object> tempMap = new HashMap<String, Object>();
				tempMap.put("user", epliteClient.getAuthorName(authorList.get(i).toString()));
				List authorRevisions = epliteClient.getAuthorRevisions(assignmentPad.getId(),
						authorList.get(i).toString(),activity.getStartDate().getTime(),activity.getEndDate().getTime());
				int wordCount = 0;
				for (int j = 0; j < authorRevisions.size(); j++) {
					int textCount = (Integer) ((Map) authorRevisions.get(j)).get("textCount") - 1;
					wordCount += textCount;
				}
				tempMap.put("wordCount", wordCount);
				list.add(tempMap);
			}
		}
		map.put("pie", list);
		return map;
	}

	public Map<String, Object> getCourseWordPie(String activityId, User user) {
		// 组内饼图 {assignment:'',group:'',pie:[{user:'',word:''}]}
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		List<CourseGroupUser> courseGroupUserList = courseGroupUserDao
				.findCourseGroupUserByCourseIdAndGroupType(assignment.getCourseId(), assignment.getAssignmentType());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("assignmentId", assignment.getId());
		map.put("assignmentName", assignment.getAssignmentName());
		int wordCount = 0;
		if (courseGroupUserList != null && courseGroupUserList.size() > 0) {
			String groupId = courseGroupUserList.get(0).getGroupId();
			List<AssignmentPad> assignmentPadList = assignmentPadDao
					.findAssignmentPadByAssignmentId(assignment.getId());
			for (int j = 0; j < assignmentPadList.size(); j++) {
				for (int i = 0; i < courseGroupUserList.size(); i++) {
					List allRevisions = epliteClient.getAllRevisions(assignmentPadList.get(j).getId(),activity.getStartDate().getTime(),activity.getEndDate().getTime());
					for (int k = 0; k < allRevisions.size(); k++) {
						int textCount = (Integer) ((Map) allRevisions.get(k)).get("textCount") - 1;
						wordCount += textCount;
					}
				}
			}
		}
		map.put("wordCount", (wordCount + 0.0) / courseGroupUserList.size());
		return map;
	}

	public Map<String, Object> getGroupVersionBar(String activityId, User user) {
		// 组内饼图 {assignment:'',group:'',pie:[{user:'',word:''}]}
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		List<CourseGroupUser> courseGroupUserList = courseService.getUserAssignmentGroup(user.getId(),
				activity.getAssignmentId(), assignment.getAssignmentType());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("assignmentId", assignment.getId());
		map.put("assignmentName", assignment.getAssignmentName());
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		if (courseGroupUserList != null && courseGroupUserList.size() > 0) {
			map.put("groupName", courseGroupUserList.get(0).getGroupName());
			String groupId = courseGroupUserList.get(0).getGroupId();
			AssignmentPad assignmentPad = assignmentService.getUserAssignmentPad(assignment.getId(), groupId);
			List authorList = epliteClient.listAuthorsOfPad(assignmentPad.getId());
			for (int i = 0; i < authorList.size(); i++) {
				Map<String, Object> tempMap = new HashMap<String, Object>();
				tempMap.put("user", epliteClient.getAuthorName(authorList.get(i).toString()));
				List authorRevisions = epliteClient.getAuthorRevisions(assignmentPad.getId(),
						authorList.get(i).toString(),activity.getStartDate().getTime(),activity.getEndDate().getTime());
				tempMap.put("versionCount", authorRevisions.size());
				list.add(tempMap);
			}
		}
		map.put("bar", list);
		return map;
	}

	public Map<String, Object> getCourseVersionBar(String activityId, User user) {
		// 组内饼图 {assignment:'',group:'',pie:[{user:'',word:''}]}
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		List<CourseGroupUser> courseGroupUserList = courseGroupUserDao
				.findCourseGroupUserByCourseIdAndGroupType(assignment.getCourseId(), assignment.getAssignmentType());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("assignmentId", assignment.getId());
		map.put("assignmentName", assignment.getAssignmentName());
		int versionCount = 0;
		if (courseGroupUserList != null && courseGroupUserList.size() > 0) {
			String groupId = courseGroupUserList.get(0).getGroupId();
			List<AssignmentPad> assignmentPadList = assignmentPadDao
					.findAssignmentPadByAssignmentId(assignment.getId());
			for (int j = 0; j < assignmentPadList.size(); j++) {
				List allRevisions = epliteClient.getAllRevisions(assignmentPadList.get(j).getId(),activity.getStartDate().getTime(),activity.getEndDate().getTime());
				versionCount += allRevisions.size();
			}
		}
		map.put("versionCount", (versionCount + 0.0) / courseGroupUserList.size());
		return map;
	}

	public Map<String, Object> getFocusLine(String activityId, User user) {
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		List<CourseGroupUser> courseGroupUserList = courseService.getUserAssignmentGroup(user.getId(),
				activity.getAssignmentId(), assignment.getAssignmentType());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("assignmentId", assignment.getId());
		map.put("assignmentName", assignment.getAssignmentName());
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		if (courseGroupUserList != null && courseGroupUserList.size() > 0) {
			map.put("groupName", courseGroupUserList.get(0).getGroupName());
			String groupId = courseGroupUserList.get(0).getGroupId();
			AssignmentPad assignmentPad = assignmentService.getUserAssignmentPad(assignment.getId(), groupId);
			List authorList = epliteClient.listAuthorsOfPad(assignmentPad.getId());
			for (int i = 0; i < authorList.size(); i++) {
				Map<String, Object> tempMap = new HashMap<String, Object>();
				tempMap.put("user", epliteClient.getAuthorName(authorList.get(i).toString()));
				List authorRevisions = epliteClient.getAuthorRevisions(assignmentPad.getId(),
						authorList.get(i).toString(),activity.getStartDate().getTime(),activity.getEndDate().getTime());
				tempMap.put("versionCount", authorRevisions.size());
				list.add(tempMap);
			}
		}
		map.put("bar", list);
		return null;
	}

	public List getPadFocus(String activityId, String userId) {
		Activity activity = activityDao.findOne(activityId);
		CourseGroupUser courseGroupUser = assignmentService.getUserAssignmentSession(activity.getAssignmentId(),
				userId);
		AssignmentPad assignmentPad = assignmentService.getUserAssignmentPad(activity.getAssignmentId(),
				courseGroupUser.getGroupId());
		List authorList = (List) epliteClient.listAuthorsOfPad(assignmentPad.getId());
		List<Object> tempList = new ArrayList<Object>();
		for (Object authorId : authorList) {
			Map<String, Object> tempMap = new HashMap<String, Object>();
			tempMap.put("user", epliteClient.getAuthorName(authorId.toString()));
			tempMap.put("focus", getUserfocus(assignmentPad.getId(), authorId.toString(),activity.getStartDate().getTime(),activity.getEndDate().getTime()));
			tempList.add(tempMap);
		}
		return tempList;
	}

	/**
	 * 获取用户某个pad的专注度
	 * 
	 * @param authorId
	 * @param padId
	 * @return [{focusValue=9, time=1458098216953},{}]
	 */
	public List getUserfocus(String padId, String authorId,long startTime,long endTime) {
		List list = epliteClient.getAuthorRevisions(padId, authorId,startTime,endTime);

		if (list != null && list.size() >= 2) {
			List<Object> tempList = new ArrayList<Object>();
			for (int i = 0; i < list.size() - 1; i++) {
				long versionTime1 = (Long) ((Map) list.get(i)).get("timestamp");
				long versionTime2 = (Long) ((Map) list.get(i + 1)).get("timestamp");
				int differTime = (int) (Math.abs(versionTime2 - versionTime1) / 1000);

				Map<String, Object> tempMap = new HashMap<String, Object>();
				tempMap.put("focus", getWeight(differTime));
				tempMap.put("time", ((Map) list.get(i + 1)).get("timestamp"));
				tempList.add(tempMap);
			}
			return tempList;
		}
		return null;
	}

	/**
	 * 获取权重值
	 * 
	 * @param differTime
	 * @param weightTree
	 * @return
	 */
	public static float getWeight(int differTime) {
		return weightTree.headMap(differTime, false).lastEntry().getValue();
	}

	/**
	 * 获得组内社会网络图
	 */
	public Map<String, Object> getMutualtRelationship(String activityId, User user) {
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		// courseGroupUserList存放所有本组组员信息
		Map<String, Object> dataMap = new HashMap<String, Object>();
		List<CourseGroupUser> courseGroupUserList = courseService.getUserAssignmentGroup(user.getId(),
				activity.getAssignmentId(), assignment.getAssignmentType());
		List<String> groupUsersList = new ArrayList<String>();
		List<Object> tempListAddComment = new ArrayList<Object>();
		List<Object> tempListAddReply = new ArrayList<Object>();
		List<Object> tempListGrade = new ArrayList<Object>();
		for (int j = 0; j < courseGroupUserList.size(); j++) {
			// 取出该用户所添加的评论的信息，addcomment阶段。

			List<Object> tempList = new ArrayList<Object>();
			List<String> commenterIdList = new ArrayList<String>();
			List<FbComment> addCommentList = new ArrayList<FbComment>();
			List<FbComment> list = new ArrayList<FbComment>();

			list = fbCommentDao.findFbCommentByAuthorIdAndAssignmentIdAndActivityId(
					courseGroupUserList.get(j).getUserId(), assignment.getId(), activityId);
			// System.out.println(list);
			for (int k = 0; k < list.size(); k++) {
				if (list.get(k).getFeedbackType().equals("0")) {
					addCommentList.add(list.get(k));
				}
			}
			// System.out.println("addCommentList"+ addCommentList);

			for (int k = 0; k < addCommentList.size(); k++) {
				boolean hasOne = false;
				if (k == 0) {
					commenterIdList.add(addCommentList.get(k).getCommenterId());
				} else {
					for (int m = 0; m < commenterIdList.size(); m++) {
						if (addCommentList.get(k).getCommenterId().equals(commenterIdList.get(m))) {
							hasOne = true;
						}
					}
					if (hasOne == false) {
						commenterIdList.add(addCommentList.get(k).getCommenterId());
					}
				}
			}
			for (int i = 0; i < commenterIdList.size(); i++) {
				int times = 0;
				boolean inTheGroup = false;
				Map<String, Object> tempMap = new HashMap<String, Object>();

				for (int k = 0; k < addCommentList.size(); k++) {
					if (commenterIdList.get(i).equals(addCommentList.get(k).getCommenterId())) {
						times++;
					}
				}
				for (int f = 0; f < courseGroupUserList.size(); f++) {
					// System.out.println("out
					// "+courseGroupUserList.get(f).getUserId()+"
					// "+commenterIdList.get(i));
					if (courseGroupUserList.get(f).getUserId().equals(commenterIdList.get(i))) {
						inTheGroup = true;
					}
				}
				if (inTheGroup) {
					tempMap.put("author", courseGroupUserList.get(j).getUserName());
					tempMap.put("commenter", userDao.findUserById(commenterIdList.get(i)).getRealname());
					tempMap.put("times", times);
					// System.out.println(tempMap);
					tempList.add(tempMap);
				}
			}
			tempListAddComment.add(tempList);
		}
		for (int j = 0; j < courseGroupUserList.size(); j++) {
			// 拿取replay的所有信息，replay阶段。
			String authorId = null;
			String commentId = null;
			List<Object> tempListB = new ArrayList<Object>();
			List<Object> tempList = new ArrayList<Object>();
			List<FbComment> temp = new ArrayList<FbComment>();
			List<FbComment> ReplyList = new ArrayList<FbComment>();
			// System.out.println(courseGroupUserList.get(j).getUserId()+"
			// "+assignment.getId());
			ReplyList = fbCommentDao.findFbCommentByAuthorIdAndCommenterIdAndAssignmentIdAndActivityId("null",
					courseGroupUserList.get(j).getUserId(), assignment.getId(), activityId);
			// System.out.println(ReplyList.size());

			for (int k = 0; k < ReplyList.size(); k++) {
				if (commentId == null) {
					commentId = ReplyList.get(k).getCommentId();
					temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(commentId,
							assignment.getId(), activityId);

					for (int n = 0; n < temp.size(); n++) {
						if (n == 0) {
							authorId = temp.get(n).getAuthorId();
						}
					}
					tempList.add(authorId);
				} else {
					boolean hasOne = false;
					commentId = ReplyList.get(k).getCommentId();
					temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(commentId,
							assignment.getId(), activityId);
					for (int n = 0; n < temp.size(); n++) {
						if (n == 0) {
							authorId = temp.get(n).getAuthorId();
						}
					}
					for (int m = 0; m < tempList.size(); m++) {
						if (tempList.get(m).equals(authorId)) {
							hasOne = true;
						}
					}
					if (hasOne == false) {
						tempList.add(authorId);
					}
				}
			}
			for (int m = 0; m < tempList.size(); m++) {
				int times = 0;
				boolean inTheGroup = false;
				Map<String, Object> tempMap = new HashMap<String, Object>();
				for (int k = 0; k < ReplyList.size(); k++) {

					temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(
							ReplyList.get(k).getCommentId(), assignment.getId(), activityId);
					for (int n = 0; n < temp.size(); n++) {
						if (n == 0) {
							authorId = temp.get(n).getAuthorId();
						}
					}
					// System.out.println(authorId+" "+tempList.get(m));
					if (authorId.equals(tempList.get(m))) {
						times++;
					}
				}
				for (int f = 0; f < courseGroupUserList.size(); f++) {
					if (courseGroupUserList.get(f).getUserId().equals(tempList.get(m))) {
						inTheGroup = true;
					}
				}
				if (inTheGroup) {
					tempMap.put("author", userDao.findUserById(tempList.get(m).toString()).getRealname());
					tempMap.put("Replyer", courseGroupUserList.get(j).getUserName());
					tempMap.put("times", times);
					tempListB.add(tempMap);
				}
			}
			tempListAddReply.add(tempListB);
		}
		for (int i = 0; i < courseGroupUserList.size(); i++) {
			// grade打分阶段，获取所有的分数回评
			List<Object> tempList = new ArrayList<Object>();
			List<String> authorList = new ArrayList<String>();
			List<FbComment> gradeList = new ArrayList<FbComment>();
			gradeList = fbCommentDao.findFbCommentByCommentTextAndCommenterIdAndAssignmentIdAndActivityId("",
					courseGroupUserList.get(i).getUserId(), assignment.getId(), activityId);
			for (int j = 0; j < gradeList.size(); j++) {
				boolean hasOne = false;
				if (j == 0) {
					authorList.add(gradeList.get(j).getAuthorId());
				} else {
					for (int m = 0; m < authorList.size(); m++) {
						if (gradeList.get(j).getAuthorId().equals((authorList.get(m)))) {
							hasOne = true;
						}
					}
					if (hasOne == false) {
						authorList.add(gradeList.get(j).getAuthorId());
					}
				}
			}
			for (int j = 0; j < authorList.size(); j++) {
				int times = 0;
				boolean inTheGroup = false;
				Map<String, Object> tempMap = new HashMap<String, Object>();
				for (int m = 0; m < gradeList.size(); m++) {
					if (gradeList.get(m).getAuthorId().equals(authorList.get(j))) {
						times++;
					}
				}
				for (int f = 0; f < courseGroupUserList.size(); f++) {
					if (courseGroupUserList.get(f).getUserId().equals(authorList.get(j))) {
						inTheGroup = true;
					}
				}
				if (inTheGroup) {
					tempMap.put("grader", courseGroupUserList.get(i).getUserName());
					tempMap.put("author", userDao.findUserById(authorList.get(j)).getRealname());
					tempMap.put("times", times);
					tempList.add(tempMap);
				}
			}
			tempListGrade.add(tempList);
		}
		for (int i = 0; i < courseGroupUserList.size(); i++) {
			groupUsersList.add(courseGroupUserList.get(i).getUserName());
		}
		dataMap.put("groupUsersList", groupUsersList);
		dataMap.put("addCommentList", tempListAddComment);
		dataMap.put("replyList", tempListAddReply);
		dataMap.put("gradeList", tempListGrade);
		//System.out.println(dataMap.toString());
		return dataMap;
	}

	public Map<String, Object> getGroupBetweenRadar(String activityId, User user) throws Exception {
		// 组间雷达图获取数据调用方法
		Map<String, Object> returnMap = new HashMap<String, Object>();
		List<Object> groupList = new ArrayList<Object>();
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		List<CommentQuestion> commentQuestions = commentQuestionDao.findByTemplateId(assignment.getReplyTemplateId());
		List<CourseGroupUser> courseGroupUserList = courseService.getUserAssignmentGroup(user.getId(),
				activity.getAssignmentId(), assignment.getAssignmentType());
		String comGroup = "";
		Group mygroup = new Group();
		if (courseGroupUserList.size() != 0) {
			mygroup = groupDao.findById(courseGroupUserList.get(0).getGroupId());
			comGroup = mygroup.getCommentGroups();
		}

		String[] comGroups = comGroup.split("\\:");
		List<String> comgroups = new ArrayList<String>();
		for (int i = 0; i < comGroups.length; i++) {
			if (!comGroups[i].equals(mygroup.getGroupNum())) {
				comgroups.add(comGroups[i]);
			}
		}
		for (int i = 0; i < comgroups.size(); i++) {
			String groupId = groupDao.findByCourseIdAndGroupTypeAndGroupNum(assignment.getCourseId(),
					assignment.getAssignmentType(), comgroups.get(i)).getId();
			List<CourseGroupUser> GroupUserList = new ArrayList<CourseGroupUser>();
			GroupUserList = courseGroupUserDao.findCourseGroupUserByGroupId(groupId);
			for (int j = 0; j < GroupUserList.size(); j++) {
				courseGroupUserList.add(GroupUserList.get(j));
			}

		}

		for (int i = 0; i < courseGroupUserList.size(); i++) {// 循环的是小组人数
			List<String> commentIDs = new ArrayList<String>();
			List<Map<String, Object>> authorList = new ArrayList<Map<String, Object>>();
			List<FbComment> list = new ArrayList<FbComment>();
			List<FbComment> latestFeedBackList = new ArrayList<FbComment>();
			List<FbComment> feedBacklist = new ArrayList<FbComment>();
			list = fbCommentDao.findFbCommentByAuthorIdAndAssignmentIdAndActivityId(
					courseGroupUserList.get(i).getUserId(), assignment.getId(), activityId);
			// System.out.println(list.size());
			for (int j = 0; j < list.size(); j++) {// 拿取到关于此人的回评评论
//				if (list.get(j).getCommentText().equals("")) {de 前
				if (list.get(j).getCommentText()==null) {
					feedBacklist.add(list.get(j));
				}else if (list.get(j).getCommentText().equals("")) {
					feedBacklist.add(list.get(j));
				}
			}
			// System.out.println("F"+feedBacklist.size());
			for (int j = 0; j < feedBacklist.size(); j++) {// 取到一共有几条评论
				if (j == 0) {
					commentIDs.add(feedBacklist.get(j).getCommentId());
				} else {
					boolean hasOne = false;
					for (int k = 0; k < commentIDs.size(); k++) {
						if (commentIDs.get(k).equals(feedBacklist.get(j).getCommentId())) {
							hasOne = true;
						}
					}
					if (hasOne == false) {
						commentIDs.add(feedBacklist.get(j).getCommentId());
					}
				}
			}
			// System.out.println("C"+commentIDs.size());
			for (int j = 0; j < commentIDs.size(); j++) {// 拿到关于某个评论最新的那条数据
				FbComment temp = null;
				long compreDate = 0;
				for (int k = 0; k < feedBacklist.size(); k++) {
					if (commentIDs.get(j).equals(feedBacklist.get(k).getCommentId())) {
						if (Long.parseLong(feedBacklist.get(k).getTimestamp()) > compreDate) {
							compreDate = Long.parseLong(feedBacklist.get(k).getTimestamp());
							temp = feedBacklist.get(k);
						}
					}
				}
				latestFeedBackList.add(temp);
			}
			// System.out.println("L"+latestFeedBackList.size());

			for (int j = 0; j < commentQuestions.size(); j++) {// 获取维度与分数
				Map<String, Object> map = new HashMap<String, Object>();
				double score = 0;
				int times = 0;
				for (int k = 0; k < latestFeedBackList.size(); k++) {
					List<FbCommentGrade> list2 = fbCommentGradeDao
							.findFbCommentByFbid(Integer.toString(latestFeedBackList.get(k).getId()));
					for (int u = 0; u < list2.size(); u++) {
						if (list2.get(u).getTemplateId().equals(commentQuestions.get(j).getId())) {
							times++;
							score += Integer.parseInt(list2.get(u).getScore());
						}
					}
				}
				if (score != 0) {
					score = score / times;
				}
				map.put("author", courseGroupUserList.get(i).getUserName());
				map.put("type", commentQuestions.get(j).getQuestion());
				map.put("score", score);
				authorList.add(map);
			}
			groupList.add(authorList);
		}
		//System.out.println(groupList);
		returnMap.put("data", groupList);
		return returnMap;
	}

	public Map<String, Object> getCourseBetweenRadar(String activityId, User user) {// 班级平均
		List<String> questionList = new ArrayList<String>();
		Map<String, Object> returnMap = new HashMap<String, Object>();
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		List<CourseGroupUser> courseGroupUserList1 = courseService.getUserAssignmentGroup(user.getId(),
				activity.getAssignmentId(), assignment.getAssignmentType());
		List<Group> groups = groupDao.findGroupByCourseIdAndGroupType(assignment.getCourseId(),
				courseGroupUserList1.get(0).getGroupType());
		List<CommentQuestion> commentQuestions = commentQuestionDao.findByTemplateId(assignment.getReplyTemplateId());
		Map<String, Double> scoreBiggest = new HashMap<String, Double>();
		Map<String, Double> scoreAverage = new HashMap<String, Double>();
		Map<String, Object> biggestMap = new HashMap<String, Object>();
		Map<String, Object> averageMap = new HashMap<String, Object>();
		List<Object> courseData = new ArrayList<Object>();
		List<Object> returnData = new ArrayList<Object>();
		for (int i = 0; i < commentQuestions.size(); i++) {
			questionList.add(commentQuestions.get(i).getQuestion());
		}
		// System.out.println(groups.size());
		for (int m = 0; m < groups.size(); m++) {
			Map<String, Double> groupScore = new HashMap<String, Double>();
			Map<String, Object> groupMap = new HashMap<String, Object>();
			List<CourseGroupUser> courseGroupUserList = courseGroupUserDao
					.findCourseGroupUserByGroupId(groups.get(m).getId());
			for (int i = 0; i < commentQuestions.size(); i++) {
				double score = 0;
				groupScore.put(commentQuestions.get(i).getQuestion(), score);
			}
			int[] courseCount=new int[commentQuestions.size()];
			for(int l=0;l<courseCount.length;l++){
				courseCount[l]=0;
			}
			for (int i = 0; i < courseGroupUserList.size(); i++) {// 循环的是小组人数
				List<String> commentIDs = new ArrayList<String>();
				List<FbComment> list = new ArrayList<FbComment>();
				List<FbComment> latestFeedBackList = new ArrayList<FbComment>();
				List<FbComment> feedBacklist = new ArrayList<FbComment>();
				list = fbCommentDao.findFbCommentByAuthorIdAndAssignmentIdAndActivityId(
						courseGroupUserList.get(i).getUserId(), assignment.getId(), activityId);
				// System.out.println(list.size());
				for (int j = 0; j < list.size(); j++) {// 拿取到关于此人的回评评论
//					if (list.get(j).getCommentText().equals("")) {
					if (list.get(j).getCommentText()==null) {
						feedBacklist.add(list.get(j));
					}else if (list.get(j).getCommentText().equals("")) {
						feedBacklist.add(list.get(j));
					}
				}
				// System.out.println("F"+feedBacklist.size());
				for (int j = 0; j < feedBacklist.size(); j++) {// 取到一共有几条评论
					if (j == 0) {
						commentIDs.add(feedBacklist.get(j).getCommentId());
					} else {
						boolean hasOne = false;
						for (int k = 0; k < commentIDs.size(); k++) {
							if (commentIDs.get(k).equals(feedBacklist.get(j).getCommentId())) {
								hasOne = true;
							}
						}
						if (hasOne == false) {
							commentIDs.add(feedBacklist.get(j).getCommentId());
						}
					}
				}
				// System.out.println("C"+commentIDs.size());
				for (int j = 0; j < commentIDs.size(); j++) {// 拿到关于某个评论最新的那条数据
					FbComment temp = null;
					long compreDate = 0;
					for (int k = 0; k < feedBacklist.size(); k++) {
						if (commentIDs.get(j).equals(feedBacklist.get(k).getCommentId())) {
							if (Long.parseLong(feedBacklist.get(k).getTimestamp()) > compreDate) {
								compreDate = Long.parseLong(feedBacklist.get(k).getTimestamp());
								temp = feedBacklist.get(k);
							}
						}
					}
					latestFeedBackList.add(temp);
				}
				// System.out.println("L"+latestFeedBackList.size());
				for (int j = 0; j < commentQuestions.size(); j++) {// 获取维度与分数
					Map<String, Object> map = new HashMap<String, Object>();
					double score = 0;
					double scoreRecord = 0;
					int times = 0;
					for (int k = 0; k < latestFeedBackList.size(); k++) {
						List<FbCommentGrade> list2 = fbCommentGradeDao.findFbCommentByFbid(Integer.toString(latestFeedBackList.get(k).getId()));
						for (int u = 0; u < list2.size(); u++) {
							if (list2.get(u).getTemplateId().equals(commentQuestions.get(j).getId())) {
								times++;
								score += Integer.parseInt(list2.get(u).getScore());
							}
						}
					}
					if (score != 0) {
						courseCount[j]++;
						score = score / times;
					}
					scoreRecord = groupScore.get(commentQuestions.get(j).getQuestion());
					scoreRecord += score;
					groupScore.put(commentQuestions.get(j).getQuestion(), scoreRecord);
				}
			}
			// System.out.println(groupScore);
			for (int i = 0; i < commentQuestions.size(); i++) {
				double scoreRecord = 0;
				scoreRecord = groupScore.get(commentQuestions.get(i).getQuestion());
				if (scoreRecord != 0) {
					scoreRecord = scoreRecord / /*courseGroupUserList.size()*/courseCount[i];
				}
				groupScore.put(commentQuestions.get(i).getQuestion(), scoreRecord);
			}
			groupMap.put("groupName", groups.get(m).getGroupName());
			groupMap.put("groupScore", groupScore);
			courseData.add(groupMap);
		}
		for (int i = 0; i < commentQuestions.size(); i++) {
			double score = 0;
			scoreBiggest.put(commentQuestions.get(i).getQuestion(), score);
		}
		for (int i = 0; i < commentQuestions.size(); i++) {
			double score = 0;
			scoreAverage.put(commentQuestions.get(i).getQuestion(), score);
		}
		for (int i = 0; i < courseData.size(); i++) {
			Map<String, Object> tempMap = new HashMap<String, Object>();
			tempMap = (Map<String, Object>) courseData.get(i);
			Map<String, Double> scoreMap = new HashMap<String, Double>();
			scoreMap = (Map<String, Double>) tempMap.get("groupScore");
			if (tempMap.get("groupName").equals(courseGroupUserList1.get(0).getGroupName())) {// 拿取本人小组的信息
				if (assignment.getAssignmentType().equals("1")) {
					tempMap.put("groupName", "本人");
				} else {
					tempMap.put("groupName", "本小组");
				}
				returnData.add(tempMap);
			}
			// 获取班级最大值
			for (int j = 0; j < commentQuestions.size(); j++) {
				if (scoreBiggest.get(commentQuestions.get(j).getQuestion()) < scoreMap
						.get(commentQuestions.get(j).getQuestion())) {
					scoreBiggest.put(commentQuestions.get(j).getQuestion(),
							scoreMap.get(commentQuestions.get(j).getQuestion()));
				}
			}
			// 班级平均值
			for (int j = 0; j < commentQuestions.size(); j++) {
				double tempScore = 0;
				tempScore = scoreAverage.get(commentQuestions.get(j).getQuestion());
				tempScore += scoreMap.get(commentQuestions.get(j).getQuestion());
				scoreAverage.put(commentQuestions.get(j).getQuestion(), tempScore);
			}
		}
		for (int i = 0; i < commentQuestions.size(); i++) {
			double tempScore = 0;
			tempScore = scoreAverage.get(commentQuestions.get(i).getQuestion());
			if (tempScore != 0) {
				scoreAverage.put(commentQuestions.get(i).getQuestion(), tempScore / groups.size());
			}
		}
		biggestMap.put("groupName", "最大值");
		biggestMap.put("groupScore", scoreBiggest);
		averageMap.put("groupName", "平均值");
		averageMap.put("groupScore", scoreAverage);
		returnData.add(biggestMap);
		returnData.add(averageMap);
		//System.out.println(returnData);
		// System.out.println(courseData);
		returnMap.put("data", returnData);

		returnMap.put("question", questionList);
		return returnMap;
	}

	public Map<String, Object> getBetweenRelationship(String activityId, User user) throws Exception {
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());
		List<CourseGroupUser> courseGroupUserList1 = courseService.getUserAssignmentGroup(user.getId(),
				activity.getAssignmentId(), assignment.getAssignmentType());
		List<Group> groups = groupDao.findGroupByCourseIdAndGroupType(assignment.getCourseId(),
				courseGroupUserList1.get(0).getGroupType());
		Map<String, Object> dataMap = new HashMap<String, Object>();
		List<Object> groupDataList = new ArrayList<Object>();
		for (int u = 0; u < groups.size(); u++) {
			// courseGroupUserList存放所有本组组员信息
			List<String> groupUsersList = new ArrayList<String>();
			Map<String, Object> groupDataMap = new HashMap<String, Object>();
			List<CourseGroupUser> courseGroupUserList = courseGroupUserDao
					.findCourseGroupUserByGroupId(groups.get(u).getId());
			List<Object> tempListAddComment = new ArrayList<Object>();
			List<Object> tempListAddReply = new ArrayList<Object>();
			List<Object> tempListGrade = new ArrayList<Object>();
			
			//拿取 addcomment数据开始
			for (int j = 0; j < courseGroupUserList.size(); j++) {
				// 取出该用户所添加的评论的信息，addcomment阶段。
				// groupUsersList.add(courseGroupUserList.get(j).getUserName());
				List<Object> tempList = new ArrayList<Object>();
				List<String> commenterIdList = new ArrayList<String>();
				List<FbComment> addCommentList = new ArrayList<FbComment>();
				List<FbComment> list = new ArrayList<FbComment>();
				list = fbCommentDao.findFbCommentByAuthorIdAndAssignmentIdAndActivityId(
						courseGroupUserList.get(j).getUserId(), assignment.getId(), activityId);
				// System.out.println(list);
				for (int k = 0; k < list.size(); k++) {
					if (list.get(k).getFeedbackType().equals("0")) {
						addCommentList.add(list.get(k));//排除grade
					}
				}
				// System.out.println("addCommentList"+ addCommentList);

				for (int k = 0; k < addCommentList.size(); k++) {
					boolean hasOne = false;
					if (k == 0) {
						commenterIdList.add(addCommentList.get(k).getCommenterId());
					} else {
						for (int m = 0; m < commenterIdList.size(); m++) {
							if (addCommentList.get(k).getCommenterId().equals(commenterIdList.get(m))) {
								hasOne = true;
							}
						}
						if (hasOne == false) {
							commenterIdList.add(addCommentList.get(k).getCommenterId());
						}
					}
				}//找到作者以author身份给 哪些人添加了评论，哪些人里不能有重复
				
				
				for (int i = 0; i < commenterIdList.size(); i++) {
					int times = 0;
					Map<String, Object> tempMap = new HashMap<String, Object>();

					for (int k = 0; k < addCommentList.size(); k++) {
						if (commenterIdList.get(i).equals(addCommentList.get(k).getCommenterId())) {
							times++;
						}
					}
					
					User checkCommenter=userDao.findUserById(commenterIdList.get(i));
					if(checkCommenter!=null){
					tempMap.put("author", courseGroupUserList.get(j).getUserName());
					tempMap.put("commenter", userDao.findUserById(commenterIdList.get(i)).getRealname());
					tempMap.put("times", times);
					// System.out.println(tempMap);
					tempList.add(tempMap);
					}
				}
				
				tempListAddComment.add(tempList);
			}
			//拿取 addcomment数据结束
			
			for (int j = 0; j < courseGroupUserList.size(); j++) {
				// 拿取replay的所有信息，replay阶段。
				String authorId = null;
				String commentId = null;
				List<Object> tempListB = new ArrayList<Object>();
				List<Object> tempList = new ArrayList<Object>();
				List<FbComment> temp = new ArrayList<FbComment>();
				List<FbComment> ReplyList = new ArrayList<FbComment>();
				// System.out.println(courseGroupUserList.get(j).getUserId()+"
				// "+assignment.getId());
				//
				// 拿取courseGroupUserList.get(j)的用户的 回复的所有评论
				ReplyList = fbCommentDao.findFbCommentByAuthorIdAndCommenterIdAndAssignmentIdAndActivityId("null",
						courseGroupUserList.get(j).getUserId(), assignment.getId(), activityId);
				// System.out.println(ReplyList.size());

				for (int k = 0; k < ReplyList.size(); k++) {//目的是拿到当前用户回复的所有评论的authorid，并且不能重复
					if (commentId == null) {
						
						commentId = ReplyList.get(k).getCommentId();
						// 拿到当前人回复的一条评论 的所有相关操作， add，reply，grade都有。
//						temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(commentId,
//								assignment.getId(), activityId);
						temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentId(commentId,
								assignment.getId());
						for (int n = 0; n < temp.size(); n++) {
							//对刚刚 查询出爱的评论集 做循环， 查找出来作者是谁。 authorid
							if (!temp.get(n).getAuthorId().equals("null")) {
								authorId = temp.get(n).getAuthorId();
							    break;
							}
						}
						tempList.add(authorId);
					} else {
						boolean hasOne = false;
						commentId = ReplyList.get(k).getCommentId();
//						temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(commentId,
//								assignment.getId(), activityId);
						temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentId(commentId,
								assignment.getId());
						for (int n = 0; n < temp.size(); n++) {
							/*if (n == 0) {//如果authorid==mode
								authorId = temp.get(n).getAuthorId();
							}*/
							if (!temp.get(n).getAuthorId().equals("null")) {
								authorId = temp.get(n).getAuthorId();
							    break;
							}
						}
						for (int m = 0; m < tempList.size(); m++) {
							if(tempList.get(m)!=null){
							if (tempList.get(m).equals(authorId)) {
								hasOne = true;
							}
							}
						}
						
						if (hasOne == false) {
							tempList.add(authorId);
						}
					}
				}
				
				
				for (int m = 0; m < tempList.size(); m++) {
					int times = 0;
					Map<String, Object> tempMap = new HashMap<String, Object>();
					for (int k = 0; k < ReplyList.size(); k++) {

						temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(
								ReplyList.get(k).getCommentId(), assignment.getId(), activityId);
						for (int n = 0; n < temp.size(); n++) {
							/*if (n == 0) {//mode
								authorId = temp.get(n).getAuthorId();
							}*/
							if (!temp.get(n).getAuthorId().equals("null")) {
								authorId = temp.get(n).getAuthorId();
							    break;
							}
						}
						if(authorId!=null){
						if (authorId.equals(tempList.get(m))) {
							times++;
						}
						}
					}
                    
					if(tempList.get(m)!=null){
					 User checkAuthor= userDao.findUserById(tempList.get(m).toString());
					 if(checkAuthor!=null){
					     tempMap.put("author", userDao.findUserById(tempList.get(m).toString()).getRealname());
					     tempMap.put("Replyer", courseGroupUserList.get(j).getUserName());
					     tempMap.put("times", times);
					     tempListB.add(tempMap);
					    }
					}
					
				}
				tempListAddReply.add(tempListB);
			}
			
			for (int i = 0; i < courseGroupUserList.size(); i++) {
				// grade打分阶段，获取所有的分数回评
				List<Object> tempList = new ArrayList<Object>();
				List<String> authorList = new ArrayList<String>();
				List<FbComment> gradeList = new ArrayList<FbComment>();
				gradeList = fbCommentDao.findFbCommentByCommentTextAndCommenterIdAndAssignmentIdAndActivityId("",
						courseGroupUserList.get(i).getUserId(), assignment.getId(), activityId);
				for (int j = 0; j < gradeList.size(); j++) {
					boolean hasOne = false;
					if (j == 0) {
						authorList.add(gradeList.get(j).getAuthorId());
					} else {
						for (int m = 0; m < authorList.size(); m++) {
							if (gradeList.get(j).getAuthorId().equals((authorList.get(m)))) {
								hasOne = true;
							}
						}
						if (hasOne == false) {
							authorList.add(gradeList.get(j).getAuthorId());
						}
					}
				}
				for (int j = 0; j < authorList.size(); j++) {
					int times = 0;
					Map<String, Object> tempMap = new HashMap<String, Object>();
					for (int m = 0; m < gradeList.size(); m++) {
						if (gradeList.get(m).getAuthorId().equals(authorList.get(j))) {
							times++;
						}
					}
					
					User checkAuthor=userDao.findUserById(authorList.get(j));
					if(checkAuthor!=null){
					tempMap.put("grader", courseGroupUserList.get(i).getUserName());
					tempMap.put("author", userDao.findUserById(authorList.get(j)).getRealname());
					tempMap.put("times", times);
					tempList.add(tempMap);
					}
				}
				tempListGrade.add(tempList);
			}
			for (int i = 0; i < courseGroupUserList.size(); i++) {
				groupUsersList.add(courseGroupUserList.get(i).getUserName());
			}
			groupDataMap.put("groupUsersList", groupUsersList);
			groupDataMap.put("addCommentList", tempListAddComment);
			groupDataMap.put("replyList", tempListAddReply);
			groupDataMap.put("gradeList", tempListGrade);
			groupDataList.add(groupDataMap);
		}
		dataMap.put("data", groupDataList);
		// System.out.println(dataMap);
		//System.out.println("end---");
		return dataMap;
	}

	public Map<String, Object> getBetweenRelationshipB(String activityId, User user) throws Exception {
		Activity activity = activityDao.findOne(activityId);
		Assignment assignment = assignmentDao.findOne(activity.getAssignmentId());

		if (assignment.getAssignmentType().equals("1")) {
			// courseGroupUserList存放所有本组组员信息
			CourseGroupUser me = courseGroupUserDao.findByUserIdAndGroupTypeAndCourseId(user.getId(), "1",
					assignment.getCourseId());
			String comGroup = groupDao.findById(me.getGroupId()).getCommentGroups();
			String[] comGroups = comGroup.split("\\:");
			List<Group> myCommentGroups = new ArrayList<Group>();
			for (int i = 0; i < comGroups.length; i++) {
				myCommentGroups.add(
						groupDao.findByCourseIdAndGroupTypeAndGroupNum(assignment.getCourseId(), "1", comGroups[i]));
			}
			List<CourseGroupUser> courseGroupUserList = new ArrayList<CourseGroupUser>();
			myCommentGroups.add(groupDao.findById(me.getGroupId()));
			for (int i = 0; i < myCommentGroups.size(); i++) {
				courseGroupUserList
						.add(courseGroupUserDao.findOneCourseGroupUserByGroupId(myCommentGroups.get(i).getId()));
			}

			Map<String, Object> dataMap = new HashMap<String, Object>();
			// List<CourseGroupUser> courseGroupUserList =
			// courseService.getUserAssignmentGroup(user.getId(),
			// activity.getAssignmentId(), assignment.getAssignmentType());
			List<String> groupUsersList = new ArrayList<String>();
			List<Object> tempListAddComment = new ArrayList<Object>();
			List<Object> tempListAddReply = new ArrayList<Object>();
			List<Object> tempListGrade = new ArrayList<Object>();

			for (int j = 0; j < courseGroupUserList.size(); j++) {
				// 取出该用户所添加的评论的信息，addcomment阶段。

				List<Object> tempList = new ArrayList<Object>();
				List<String> commenterIdList = new ArrayList<String>();
				List<FbComment> addCommentList = new ArrayList<FbComment>();
				List<FbComment> list = new ArrayList<FbComment>();

				list = fbCommentDao.findFbCommentByAuthorIdAndAssignmentIdAndActivityId(
						courseGroupUserList.get(j).getUserId(), assignment.getId(), activityId);
				// System.out.println(list);
				for (int k = 0; k < list.size(); k++) {
					if (list.get(k).getFeedbackType().equals("0")) {
						addCommentList.add(list.get(k));
					}
				}
				// System.out.println("addCommentList"+ addCommentList);

				for (int k = 0; k < addCommentList.size(); k++) {
					boolean hasOne = false;
					if (k == 0) {
						commenterIdList.add(addCommentList.get(k).getCommenterId());
					} else {
						for (int m = 0; m < commenterIdList.size(); m++) {
							if (addCommentList.get(k).getCommenterId().equals(commenterIdList.get(m))) {
								hasOne = true;
							}
						}
						if (hasOne == false) {
							commenterIdList.add(addCommentList.get(k).getCommenterId());
						}
					}
				}
				for (int i = 0; i < commenterIdList.size(); i++) {
					int times = 0;
					boolean inTheGroup = false;
					Map<String, Object> tempMap = new HashMap<String, Object>();

					for (int k = 0; k < addCommentList.size(); k++) {
						if (commenterIdList.get(i).equals(addCommentList.get(k).getCommenterId())) {
							times++;
						}
					}
					for (int f = 0; f < courseGroupUserList.size(); f++) {
						// System.out.println("out
						// "+courseGroupUserList.get(f).getUserId()+"
						// "+commenterIdList.get(i));
						if (courseGroupUserList.get(f).getUserId().equals(commenterIdList.get(i))) {
							inTheGroup = true;
						}
					}
					if (inTheGroup) {
						tempMap.put("author", courseGroupUserList.get(j).getUserName());
						tempMap.put("commenter", userDao.findUserById(commenterIdList.get(i)).getRealname());
						tempMap.put("times", times);
						// System.out.println(tempMap);
						tempList.add(tempMap);
					}
				}
				tempListAddComment.add(tempList);
			}
			for (int j = 0; j < courseGroupUserList.size(); j++) {
				// 拿取replay的所有信息，replay阶段。
				String authorId = null;
				String commentId = null;
				List<Object> tempListB = new ArrayList<Object>();
				List<Object> tempList = new ArrayList<Object>();
				List<FbComment> temp = new ArrayList<FbComment>();
				List<FbComment> ReplyList = new ArrayList<FbComment>();
				// System.out.println(courseGroupUserList.get(j).getUserId()+"
				// "+assignment.getId());
				ReplyList = fbCommentDao.findFbCommentByAuthorIdAndCommenterIdAndAssignmentIdAndActivityId("null",
						courseGroupUserList.get(j).getUserId(), assignment.getId(), activityId);
				// System.out.println(ReplyList.size());

				for (int k = 0; k < ReplyList.size(); k++) {
					if (commentId == null) {
						commentId = ReplyList.get(k).getCommentId();
						temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(commentId,
								assignment.getId(), activityId);

						for (int n = 0; n < temp.size(); n++) {
							if (n == 0) {
								authorId = temp.get(n).getAuthorId();
							}
						}
						tempList.add(authorId);
					} else {
						boolean hasOne = false;
						commentId = ReplyList.get(k).getCommentId();
						temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(commentId,
								assignment.getId(), activityId);
						for (int n = 0; n < temp.size(); n++) {
							if (n == 0) {
								authorId = temp.get(n).getAuthorId();
							}
						}
						for (int m = 0; m < tempList.size(); m++) {
							if (tempList.get(m).equals(authorId)) {
								hasOne = true;
							}
						}
						if (hasOne == false) {
							tempList.add(authorId);
						}
					}
				}
				for (int m = 0; m < tempList.size(); m++) {
					int times = 0;
					boolean inTheGroup = false;
					Map<String, Object> tempMap = new HashMap<String, Object>();
					for (int k = 0; k < ReplyList.size(); k++) {

						temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(
								ReplyList.get(k).getCommentId(), assignment.getId(), activityId);
						for (int n = 0; n < temp.size(); n++) {
							if (n == 0) {
								authorId = temp.get(n).getAuthorId();
							}
						}
						// System.out.println(authorId+" "+tempList.get(m));
						if (authorId.equals(tempList.get(m))) {
							times++;
						}
					}
					for (int f = 0; f < courseGroupUserList.size(); f++) {
						if (courseGroupUserList.get(f).getUserId().equals(tempList.get(m))) {
							inTheGroup = true;
						}
					}
					if (inTheGroup) {
						tempMap.put("author", userDao.findUserById(tempList.get(m).toString()).getRealname());
						tempMap.put("Replyer", courseGroupUserList.get(j).getUserName());
						tempMap.put("times", times);
						tempListB.add(tempMap);
					}
				}
				tempListAddReply.add(tempListB);
			}
			for (int i = 0; i < courseGroupUserList.size(); i++) {
				// grade打分阶段，获取所有的分数回评
				List<Object> tempList = new ArrayList<Object>();
				List<String> authorList = new ArrayList<String>();
				List<FbComment> gradeList = new ArrayList<FbComment>();
				gradeList = fbCommentDao.findFbCommentByCommentTextAndCommenterIdAndAssignmentIdAndActivityId("",
						courseGroupUserList.get(i).getUserId(), assignment.getId(), activityId);
				for (int j = 0; j < gradeList.size(); j++) {
					boolean hasOne = false;
					if (j == 0) {
						authorList.add(gradeList.get(j).getAuthorId());
					} else {
						for (int m = 0; m < authorList.size(); m++) {
							if (gradeList.get(j).getAuthorId().equals((authorList.get(m)))) {
								hasOne = true;
							}
						}
						if (hasOne == false) {
							authorList.add(gradeList.get(j).getAuthorId());
						}
					}
				}
				for (int j = 0; j < authorList.size(); j++) {
					int times = 0;
					boolean inTheGroup = false;
					Map<String, Object> tempMap = new HashMap<String, Object>();
					for (int m = 0; m < gradeList.size(); m++) {
						if (gradeList.get(m).getAuthorId().equals(authorList.get(j))) {
							times++;
						}
					}
					for (int f = 0; f < courseGroupUserList.size(); f++) {
						if (courseGroupUserList.get(f).getUserId().equals(authorList.get(j))) {
							inTheGroup = true;
						}
					}
					if (inTheGroup) {
						tempMap.put("grader", courseGroupUserList.get(i).getUserName());
						tempMap.put("author", userDao.findUserById(authorList.get(j)).getRealname());
						tempMap.put("times", times);
						tempList.add(tempMap);
					}
				}
				tempListGrade.add(tempList);
			}
			for (int i = 0; i < courseGroupUserList.size(); i++) {
				groupUsersList.add(courseGroupUserList.get(i).getUserName());
			}
			dataMap.put("groupUsersList", groupUsersList);
			dataMap.put("addCommentList", tempListAddComment);
			dataMap.put("replyList", tempListAddReply);
			dataMap.put("gradeList", tempListGrade);
			List<Object> groupDataList = new ArrayList<Object>();
			Map<String, Object> groupDataMap = new HashMap<String, Object>();
			groupDataList.add(dataMap);
			groupDataMap.put("data", groupDataList);
			//System.out.println(dataMap.toString());
			return groupDataMap;
		} //小组类型是1 结束   ，单人小组  
		
		
		else {
			List<CourseGroupUser> courseGroupUserList1 = courseService.getUserAssignmentGroup(user.getId(),
					activity.getAssignmentId(), assignment.getAssignmentType());
			// List<Group>
			// groups=groupDao.findGroupByCourseIdAndGroupType(assignment.getCourseId(),courseGroupUserList1.get(0).getGroupType());
			Map<String, Object> dataMap = new HashMap<String, Object>();
			List<Object> groupDataList = new ArrayList<Object>();
			CourseGroupUser myUser = courseGroupUserDao.findByUserIdAndGroupTypeAndCourseId(user.getId(), "2",
					assignment.getCourseId());
			Group group = groupDao.findById(myUser.getGroupId());
			String comgroups = group.getCommentGroups();
			String[] commentGroupNum = comgroups.split("\\:");
			List<Group> groups = new ArrayList<Group>();
			for (int i = 0; i < commentGroupNum.length; i++) {
				groups.add(groupDao.findByGroupNumAndGroupTypeAndCourseId(commentGroupNum[i], "2",
						assignment.getCourseId()));
			}
			groups.add(group);

			for (int u = 0; u < groups.size(); u++) {
				// courseGroupUserList存放所有本组组员信息
				List<String> groupUsersList = new ArrayList<String>();
				Map<String, Object> groupDataMap = new HashMap<String, Object>();
				List<CourseGroupUser> courseGroupUserList = courseGroupUserDao
						.findCourseGroupUserByGroupId(groups.get(u).getId());
				List<Object> tempListAddComment = new ArrayList<Object>();
				List<Object> tempListAddReply = new ArrayList<Object>();
				List<Object> tempListGrade = new ArrayList<Object>();
				for (int j = 0; j < courseGroupUserList.size(); j++) {
					// 取出该用户所添加的评论的信息，addcomment阶段。
					// groupUsersList.add(courseGroupUserList.get(j).getUserName());
					List<Object> tempList = new ArrayList<Object>();
					List<String> commenterIdList = new ArrayList<String>();
					List<FbComment> addCommentList = new ArrayList<FbComment>();
					List<FbComment> list = new ArrayList<FbComment>();
					list = fbCommentDao.findFbCommentByAuthorIdAndAssignmentIdAndActivityId(
							courseGroupUserList.get(j).getUserId(), assignment.getId(), activityId);
					// System.out.println(list);
					for (int k = 0; k < list.size(); k++) {
						if (list.get(k).getFeedbackType().equals("0")) {
							addCommentList.add(list.get(k));
						}
					}
					// System.out.println("addCommentList"+ addCommentList);

					for (int k = 0; k < addCommentList.size(); k++) {
						boolean hasOne = false;
						if (k == 0) {
							commenterIdList.add(addCommentList.get(k).getCommenterId());
						} else {
							for (int m = 0; m < commenterIdList.size(); m++) {
								if (addCommentList.get(k).getCommenterId().equals(commenterIdList.get(m))) {
									hasOne = true;
								}
							}
							if (hasOne == false) {
								commenterIdList.add(addCommentList.get(k).getCommenterId());
							}
						}
					}
					for (int i = 0; i < commenterIdList.size(); i++) {
						int times = 0;
						Map<String, Object> tempMap = new HashMap<String, Object>();

						for (int k = 0; k < addCommentList.size(); k++) {
							if (commenterIdList.get(i).equals(addCommentList.get(k).getCommenterId())) {
								times++;
							}
						}
						
						User checkCommenter=userDao.findUserById(commenterIdList.get(i));
						if (checkCommenter!=null) {
						tempMap.put("author", courseGroupUserList.get(j).getUserName());
						tempMap.put("commenter", userDao.findUserById(commenterIdList.get(i)).getRealname());
						tempMap.put("times", times);
						tempList.add(tempMap);
						}
					}
					
					tempListAddComment.add(tempList);
				}
				
				
				for (int j = 0; j < courseGroupUserList.size(); j++) {
					// 拿取replay的所有信息，replay阶段。
					String authorId = null;
					String commentId = null;
					List<Object> tempListB = new ArrayList<Object>();
					List<Object> tempList = new ArrayList<Object>();
					List<FbComment> temp = new ArrayList<FbComment>();
					List<FbComment> ReplyList = new ArrayList<FbComment>();
					// System.out.println(courseGroupUserList.get(j).getUserId()+"
					// "+assignment.getId());
					//当前人以回复者的身份回复了多少条评论
					ReplyList = fbCommentDao.findFbCommentByAuthorIdAndCommenterIdAndAssignmentIdAndActivityId("null",
							courseGroupUserList.get(j).getUserId(), assignment.getId(), activityId);
					// System.out.println(ReplyList.size());

					for (int k = 0; k < ReplyList.size(); k++) {
						if (commentId == null) {
							commentId = ReplyList.get(k).getCommentId();
//							temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(commentId,
//									assignment.getId(), activityId);
							temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentId(commentId,
									assignment.getId());
							for (int n = 0; n < temp.size(); n++) {
								if (!temp.get(n).getAuthorId().equals("null")) {
									authorId = temp.get(n).getAuthorId();
									break;
								}
							}
							tempList.add(authorId);
						} else {
							boolean hasOne = false;
							commentId = ReplyList.get(k).getCommentId();
//							temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(commentId,
//									assignment.getId(), activityId);
							temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentId(commentId,
									assignment.getId());
							for (int n = 0; n < temp.size(); n++) {
								/*if (n == 0) {
									authorId = temp.get(n).getAuthorId();
								}*/
								if (!temp.get(n).getAuthorId().equals("null")) {
									authorId = temp.get(n).getAuthorId();
									break;
								}
							}
							for (int m = 0; m < tempList.size(); m++) {
								if (tempList.get(m).equals(authorId)) {
									hasOne = true;
								}
							}
							if (hasOne == false) {
								tempList.add(authorId);
							}
						}
					}
					for (int m = 0; m < tempList.size(); m++) {
						int times = 0;
						Map<String, Object> tempMap = new HashMap<String, Object>();
						for (int k = 0; k < ReplyList.size(); k++) {

							temp = fbCommentDao.findFbCommentByCommentIdAndAssignmentIdAndActivityId(
									ReplyList.get(k).getCommentId(), assignment.getId(), activityId);
							for (int n = 0; n < temp.size(); n++) {
								/*if (n == 0) {
									authorId = temp.get(n).getAuthorId();
								}*/
								if (!temp.get(n).getAuthorId().equals("null")) {
									authorId = temp.get(n).getAuthorId();
									break;
								}
							}
							// System.out.println(authorId+" "+tempList.get(m));
							if (authorId.equals(tempList.get(m))) {
								times++;
							}
						}

						tempMap.put("author", userDao.findUserById(tempList.get(m).toString()).getRealname());
						tempMap.put("Replyer", courseGroupUserList.get(j).getUserName());
						tempMap.put("times", times);
						tempListB.add(tempMap);
					}
					tempListAddReply.add(tempListB);
				}
				for (int i = 0; i < courseGroupUserList.size(); i++) {
					// grade打分阶段，获取所有的分数回评
					List<Object> tempList = new ArrayList<Object>();
					List<String> authorList = new ArrayList<String>();
					List<FbComment> gradeList = new ArrayList<FbComment>();
					gradeList = fbCommentDao.findFbCommentByCommentTextAndCommenterIdAndAssignmentIdAndActivityId("",
							courseGroupUserList.get(i).getUserId(), assignment.getId(), activityId);
					for (int j = 0; j < gradeList.size(); j++) {
						boolean hasOne = false;
						if (j == 0) {
							authorList.add(gradeList.get(j).getAuthorId());
						} else {
							for (int m = 0; m < authorList.size(); m++) {
								if (gradeList.get(j).getAuthorId().equals((authorList.get(m)))) {
									hasOne = true;
								}
							}
							if (hasOne == false) {
								authorList.add(gradeList.get(j).getAuthorId());
							}
						}
					}
					for (int j = 0; j < authorList.size(); j++) {
						int times = 0;
						Map<String, Object> tempMap = new HashMap<String, Object>();
						for (int m = 0; m < gradeList.size(); m++) {
							if (gradeList.get(m).getAuthorId().equals(authorList.get(j))) {
								times++;
							}
						}
						User checkAuthor=userDao.findUserById(authorList.get(j));
						if(checkAuthor!=null){
						tempMap.put("grader", courseGroupUserList.get(i).getUserName());
						tempMap.put("author", userDao.findUserById(authorList.get(j)).getRealname());
						tempMap.put("times", times);
						tempList.add(tempMap);
						}
					}
					tempListGrade.add(tempList);
				}
				for (int i = 0; i < courseGroupUserList.size(); i++) {
					groupUsersList.add(courseGroupUserList.get(i).getUserName());
				}
				groupDataMap.put("groupUsersList", groupUsersList);
				groupDataMap.put("addCommentList", tempListAddComment);
				groupDataMap.put("replyList", tempListAddReply);
				groupDataMap.put("gradeList", tempListGrade);
				groupDataList.add(groupDataMap);
			}
			dataMap.put("data", groupDataList);
			// System.out.println(dataMap);
			return dataMap;
		}
	}
    
	/*
	 * 获取    是否 给出组内互评建议结果       组内所有人 给自己打分完毕才允许前端  输出 建议  
	 */
	@Override
	public String getGroupAdviceResult(String activityId, User user) {
		
		//1 找出 小组人数
		   String assignmentId;
		   String courseId;
		   String groupId;
		   String assignmentPadId;
		   assignmentId=activityDao.findOne(activityId).getAssignmentId();
		   courseId=assignmentDao.findOne(assignmentId).getCourseId();
		   groupId=courseGroupUserDao.findByUserIdAndGroupTypeAndCourseId(user.getId(),"2",courseId).getGroupId();
		   List<CourseGroupUser> groupUsers=courseGroupUserDao.findCourseGroupUserByGroupId(groupId);
		   assignmentPadId=assignmentPadDao.findAssignmentPadByAssignmentIdAndGroupId(assignmentId, groupId).getId();
	   //2 找出给 user 进行过 组内评价的人数   
		   List<Comment> comments=commentDao.findByAssignmentPadIdAndAuthorId(assignmentPadId,user.getId());
		   int count=0;
		   for(int i=0;i<groupUsers.size();i++){
			   boolean hasOne=false;
			   for(int j=0;j<comments.size();j++){
				      if(comments.get(j).getCommenterId().equals(groupUsers.get(i).getUserId())){
					         if(hasOne==false){
					        	 count++;
					        	 hasOne=true;
					         }
				      }
			   }
		   }
		   
		   if(count>=(groupUsers.size()-1)){
			  return "true";
		   }
		   
		   
		return "false";
	}
    
	//获取所有文本分析相关内容进行分析
	@Override
	public Map<String,String> getTextAysContents(String padId, String activityId, User user) {
		Map<String,String> resMap=new HashMap<String, String>();
		List<CourseGroupUser> users=new ArrayList<CourseGroupUser>();
		List<String>  textRes= new ArrayList<String>();
		Activity activity = activityDao.findActivityById(activityId);
		Assignment assignment = assignmentDao.findAssignmentById(activity.getAssignmentId());
		CourseGroupUser cgUser =courseGroupUserDao.findCourseGroupUserByCourseIdAndUserIdAndGroupType(assignment.getCourseId(),user.getId(),assignment.getAssignmentType());
		//出错了
		List<CourseGroupUser> cus=courseGroupUserDao.findCourseGroupUsersByCourseIdAndUserIdAndGroupType(assignment.getCourseId(),user.getId(),assignment.getAssignmentType());
		String nowGroupId="";//本次作业的小组id
		for (int i = 0; i < cus.size(); i++) {
			//一个人 可能参加两次同样类型的作业
			String s1=cus.get(i).getGroupId()+"$"+assignment.getAssignmentName();
			AssignmentPad asp=assignmentPadDao.findOne(cus.get(i).getGroupId()+"$"+assignment.getAssignmentName());
			if (asp!=null) {
			  if (asp.getAssignmentId().equals(assignment.getId())||asp.getAssignmentId()==assignment.getId()) {
				//说明是本次作业的组
		    	   nowGroupId=cus.get(i).getGroupId();
			     }
			}
		}	
	    //把 本人封装进去
		Group group=groupDao.findById(nowGroupId);
		String groupS=group.getCommentGroups();
		String[] comGroups=groupS.split(":");
		String assignmentPadId=cgUser.getGroupId()+"$"+assignment.getAssignmentName();
		Map<String, Object>  padText=new HashMap<String, Object>();
	 	padText=epliteClient.getText(assignmentPadId);
	    String text=(String) padText.get("text");
	    resMap.put(cgUser.getUserName(),text);		
		for (int i = 0; i < comGroups.length; i++) {
			Group temGroup=groupDao.findByCourseIdAndGroupTypeAndGroupNum(assignment.getCourseId(),group.getGroupType(),comGroups[i]);
			CourseGroupUser tempUser=courseGroupUserDao.findOneCourseGroupUserByGroupId(temGroup.getId());
			String asPadId=temGroup.getId()+"$"+assignment.getAssignmentName();
			Map<String, Object>  pdText=new HashMap<String, Object>();
		 	pdText=epliteClient.getText(asPadId);
		    String pt=(String) pdText.get("text");
		    resMap.put(tempUser.getUserName(),pt);		
		}
		return resMap;
	}
    
	
	
}
